package com.automannn.atm_back.modules.codeGenerator.entity;

import lombok.Data;

import java.io.Serializable;

/**
 * @author chenkh
 * @time 2020/6/28 16:52
 */
@Data
public class ColumnEntity implements Serializable {
    private static final long serialVersionUID = 1L;
    private static final String FORM_ITEM_RULES = "[{\"precision\":\"%s\",{\"scale\":\"%s\",{\"maxLength\":\"%s\",{\"nullable\":\"%s\"}]";
    private String name;
    private String type;
    private String comment;
    private String precision;
    private String scale;
    private String maxLength;
    private String nullable;

    public ColumnConfigEntity toColumnConfigEntity() {
        //注意，这里只是转换成原始的数据配置，更多的配置需要在配置面板进行自定义
        ColumnConfigEntity columnConfigEntity = new ColumnConfigEntity();
        columnConfigEntity.setSrcName(name);
        columnConfigEntity.setTargetName(name);
        columnConfigEntity.setComment(comment);
        columnConfigEntity.setLabelName(comment);
        columnConfigEntity.setVagueConfigCode(name);
        columnConfigEntity.setType(type);
        columnConfigEntity.setShortType(type);
        columnConfigEntity.setFormItemRules(String.format(FORM_ITEM_RULES,precision,scale,maxLength,nullable));
        columnConfigEntity.setFormItemType(type);
        columnConfigEntity.setHidden("0");
        columnConfigEntity.setRequire("1");
        columnConfigEntity.setFormItemSourceType(type);
        return columnConfigEntity;
    }
}
